import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/widget/image/base_image.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';

class ItemHeader extends StatelessWidget {
  dynamic provider;

  ItemHeader({Key key, this.provider}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 62.w,
      padding: EdgeInsets.only(
        left: 18.w,
        right: 18.w,
      ),
      decoration: BoxDecoration(
        color: Colors.white,
        boxShadow: [
          BoxShadow(color: Color.fromRGBO(0, 10, 27, .05), blurRadius: 10, offset: Offset(2, 3), spreadRadius: 3.0),
        ],
        borderRadius: BorderRadius.circular(
          16.w,
        ),
      ),
      child: Row(
        children: <Widget>[
          Expanded(
              child: Row(
            children: <Widget>[
              Text(
                "门店评分：",
                style: TextStyleConstant().normal_1_26,
              ),
              StartShow(startFraction: provider?.averageScore ?? 0),
              Text(
                " ${provider?.averageScore ?? 0}分",
                style: TextStyleConstant().normal_1_26,
              ),
            ],
          )),
          RichText(
            text: TextSpan(children: <TextSpan>[
              TextSpan(
                text: "服务满意率:",
                style: TextStyleConstant().normal_1_26,
              ),
              TextSpan(
                text: "${provider?.goodCommentRate ?? 0}%",
                style: TextStyleConstant().blue_26,
              ),
            ]),
          ),
        ],
      ),
    );
  }
}

class BottomClipper extends CustomClipper<Path> {
  num startFraction; //分数
  num str; //index
  BottomClipper({this.startFraction, this.str}) : super();

  @override
  Path getClip(Size size) {
    if (startFraction >= str) {
      var path = Path()..close();
      return path;
    }

    if (startFraction.ceil() == str) {
      var path = Path()
        ..lineTo(size.width * ((startFraction) - (str - 1)), 0)
        ..lineTo(size.width * ((startFraction) - (str - 1)), size.height)
        ..lineTo(size.width, size.height)
        ..lineTo(size.width, 0)
        ..close();
      return path;
    }
    if (startFraction.ceil() < str) {
      var path = Path()
        ..lineTo(0, 0)
        ..lineTo(size.width, 0)
        ..lineTo(size.width, size.height)
        ..lineTo(0, size.height)
        ..close();
      return path;
    }
  }

  @override
  bool shouldReclip(CustomClipper<Path> oldClipper) {
    return true;
  }
}

class StartShow extends StatelessWidget {
  final num startFraction;

  const StartShow({Key key, this.startFraction}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        1,
        2,
        3,
        4,
        5,
      ]
          .map((str) => Container(
              padding: EdgeInsets.symmetric(
                horizontal: 2.w,
              ),
              child: Stack(
                children: <Widget>[
                  BaseImage(
                    'assets/image/store_evaluate_start01.png',
                    width: 33.w,
                    height: 33.w,
                  ),
                  Positioned(
                    child: ClipPath(
                      clipper: BottomClipper(startFraction: startFraction, str: str), //路径
                      child: BaseImage(
                        'assets/image/store_evaluate_start02.png',
                        width: 34.w,
                        height: 34.w,
                      ),
                    ),
                  )
                ],
              )))
          .toList(),
    );
  }
}
